package com.git.util;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.allfirst.service.param.LimitsResult;
import com.allfirst.service.param.NodeInfo;
import com.allfirst.service.param.PersonInfoResult;

public class DecodeUtil {

	public static String getDecode(String str){
		String dcstr = "";
		try {
			dcstr = java.net.URLDecoder.decode(str,"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return dcstr;
		
	}
	
	
	public static List<NodeInfo> getNodeInfos(List<NodeInfo> reports) {
		if (reports != null) {
			for (NodeInfo nodeInfo : reports) {
				nodeInfo.setNodeId(getDecode(nodeInfo.getNodeId()));
				nodeInfo.setNodeName(getDecode(nodeInfo.getNodeName()));
				nodeInfo.setReportPath(getDecode(nodeInfo.getReportPath()));
				nodeInfo.setNodeType(getDecode(nodeInfo.getNodeType()));
				nodeInfo.setParentId(getDecode(nodeInfo.getParentId()));
				nodeInfo.setSearchPath(getDecode(nodeInfo.getSearchPath()));
			}
		}
		return reports;
	}


	public static List<PersonInfoResult> getPersonByName(List<PersonInfoResult> persons){
		if(persons != null){
			
			for (PersonInfoResult personInfoResult : persons) {
				personInfoResult.setEmail(getDecode(personInfoResult.getEmail()));
				personInfoResult.setMobileNum(getDecode(personInfoResult.getMobileNum()));
				personInfoResult.setName(getDecode(personInfoResult.getName()));
				personInfoResult.setOrganization(getDecode(personInfoResult.getOrganization()));
				personInfoResult.setPhoneNum(getDecode(personInfoResult.getPhoneNum()));
				personInfoResult.setSex(getDecode(personInfoResult.getSex()));
				personInfoResult.setUserId(getDecode(personInfoResult.getUserId()));
			}
		}
		
		return persons;
	}
	
	public static PersonInfoResult getPersonById(PersonInfoResult personInfoResult){
		
		personInfoResult.setEmail(getDecode(personInfoResult.getEmail()));
		personInfoResult.setMobileNum(getDecode(personInfoResult.getMobileNum()));
		personInfoResult.setName(getDecode(personInfoResult.getName()));
		personInfoResult.setOrganization(getDecode(personInfoResult.getOrganization()));
		personInfoResult.setPhoneNum(getDecode(personInfoResult.getPhoneNum()));
		personInfoResult.setSex(getDecode(personInfoResult.getSex()));
		personInfoResult.setUserId(getDecode(personInfoResult.getUserId()));
		
		return personInfoResult;
	}
	
	public static LimitsResult getLimitsResult(LimitsResult limitsResult){
		
		limitsResult.setDeleteLimit(getDecode(limitsResult.getDeleteLimit()));
		limitsResult.setInsertLimit(getDecode(limitsResult.getInsertLimit()));
		limitsResult.setOrganization(getDecode(limitsResult.getOrganization()));
		limitsResult.setUpdateLimit(getDecode(limitsResult.getUpdateLimit()));
		limitsResult.setUserId(getDecode(limitsResult.getUserId()));
		limitsResult.setViewLimit(getDecode(limitsResult.getViewLimit()));
		
		return limitsResult;
	}

}
